let temperatures = [73,74,75,71,69,72,76,73]
//维护一个单调递减的栈
//
var dailyTemperatures = function(temperatures) {
    const len = temperatures.length;
    const stack = [];
    const res = (new Array(len)).fill(0);

    for(let i = 0;i<len;i++){
        //
        while(stack.length&&temperatures[i]>temperatures[stack[stack.length-1]]){
            const top = stack.pop();
            res[top] = i-top;
        }
        stack.push(i);
    }
    return res;
}
console.log(dailyTemperatures(temperatures));
